${r'<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="'}${packageName}.mapper.${poName}${r'Mapper">'}
<!--对象映射-->
${r"<resultMap "} type="${packageName}.domain.${poName}" id="BaseResultMap">
<#if columnBeanList?exists>
    <#list columnBeanList as model>
        <#if (model.columnType = 'INT' )>
            <result property="${model.attrname}" column="${model.columnName}" jdbcType="INTEGER"/>
        <#elseif (model.columnType = 'DATETIME')>
            <result property="${model.attrname}" column="${model.columnName}" jdbcType="TIMESTAMP"/>
        <#else >
            <result property="${model.attrname}" column="${model.columnName}" jdbcType="${model.columnType}"/>
        </#if>
    </#list>
</#if>
</resultMap>

<!--查询单个-->
${r'<select id="queryById" resultMap="BaseResultMap">'}
select
${allSqlColumn}
from ${tableName}
where id =  ${r"#{id}"}
</select>

<!--条件查询-->
${r'<select id="queryList" resultMap="BaseResultMap">'}
select
${allSqlColumn}
from ${tableName}
where 1=1
<#if columnBeanList?exists>
    <#list columnBeanList as model>
        ${r' <if test="'}${model.attrname}${r' != null ">'}
        and ${model.columnName} = ${r"#{"} ${model.attrname} ${r"}
           </if>"}
    </#list>
</#if>
order by id desc
</select>
<!--查询数据量-->
${r'<select id="queryListCount" resultMap="BaseResultMap">'}
select
count(1)
from ${tableName}
where 1=1
<#if columnBeanList?exists>
    <#list columnBeanList as model>
        ${r' <if test="'}${model.attrname}${r' != null ">'}
        and ${model.columnName} = ${r"#{"} ${model.attrname} ${r"}
           </if>"}
    </#list>
</#if>
</select>

<!--批量插入-->
<!--insert  ignore into xxxx-->
<!--replace into  xxxx-->
${r'<insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">'}
insert into  ${tableName}
(${allSqlColumn})
values
${r'<foreach collection="list" item="item" separator=",">'}
(
<#if columnBeanList?exists>
    <#list columnBeanList as model>
        ${r"#{item."}${model.attrname}${r"}"},
    </#list>
</#if>
)
</foreach>
</insert>

<!--批量更新-->
${r' <update id="updateBatch" parameterType="java.util.Collection">
           <foreach collection="list" item="item" index="index" separator=";"> '}
UPDATE ${tableName}
<set>
    <#if columnBeanList ? exists>
        <#list columnBeanList as model>
            ${model.columnName} =  ${r"#{item."}${model.attrname} ${r"}"},
        </#list>
    </#if>
</set>
WHERE id=${r"#{item.id} "}
</foreach>
</update>

<!--通过主键修改数据-->
${r'<update id="updateById">'}
update ${tableName}
<set>
    <#if columnBeanList ? exists>
        <#list columnBeanList as model>
            ${r' <if test="'}${model.attrname}${r' != null ">'}
            ${model.columnName} =  ${r"#{ "} ${model.attrname} ${r"}"},
            </if>
        </#list>
    </#if>

</set>
where id = ${r"#{id}"}
</update>

<!--通过主键删除-->
${r'<delete id="deleteById">'}
delete
from ${tableName}
where id = ${r"#{id}"}
</delete>
${r"</mapper> "}
